package code;
import java.util.ArrayList;
import models.TreeNode;
public class PrintFromTopToBottom {

    public ArrayList<Integer> Solution(TreeNode root){
        ArrayList<Integer> re = new ArrayList<>();
        ArrayList<TreeNode> q = new ArrayList<>();
        if(root==null){
            return re;
        }
        q.add(root);
        while(q.size()>0){
            TreeNode t = q.remove(0);
            re.add(t.val);
            if(root.left!=null){
                q.add(root.left);
            }
            if(root.right!=null){
                q.add(root.right);
            }
        }
        return re;
    }

}
